package main

import (
	"fmt"
	"io"
	"os"
)

// Author : CSR丶WARRIOR
// Time ： 2020/10/21  21:21
// TOOLS : GoLand
// FILENAME : copyFile.go
// STATEMENT: 拷贝文件案例

func main() {
	copyFile()
}
func copyFile() {
	//读取文件
	srcFileName := "D:\\WARRIOR\\Go\\go\\src\\golang_suse\\advanceModule\\IO\\textFileHandle\\testWrite.txt"
	destFileName := "D:\\WARRIOR\\Go\\go\\src\\golang_suse\\advanceModule\\IO\\textFileHandle\\case\\bak.txt"
	srcFile, err := os.Open(srcFileName)
	destFile, err1 := os.Create(destFileName)
	if err != nil {
		fmt.Println(err)
	}
	if err1 != nil {
		fmt.Println(err1)
	}
	var slice = make([]byte, 100)
	for {
		readNum, err3 := srcFile.Read(slice)
		_, err4 := destFile.Write(slice[:readNum])
		if err4 != nil {
			fmt.Println(err4)
		}
		if err3 == io.EOF {
			break
		}
	}
	defer srcFile.Close()
	defer destFile.Close()
}
